package com.scuec.groupfive.Controller;

import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.PastExam;
import com.scuec.groupfive.service.PastExamService;
import com.scuec.groupfive.vo.PastExamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/pastexam")
@CrossOrigin
public class PastExamController {

    @Autowired
    private PastExamService pastExamService;

    // 分页列表显示所有考试记录
    @GetMapping("/pages")
    public PageInfo<PastExam> getPastExamPages(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return pastExamService.getPastExamPages(pageNum, pageSize);
    }

    // 根据用户名查询考试记录（分页）
    //http://localhost:8080/pastexam/findByUsername?username=emma_w
    @GetMapping("/findByUsername")
    public PageInfo<PastExamVO> getPastExamByUsername(
            @RequestParam String username,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return pastExamService.getPastExamByUsername(username, pageNum, pageSize);
    }

    // 新增：根据用户名获取考试统计信息
    // 访问地址：http://localhost:8080/pastexam/stats?username=emma_w
    @GetMapping("/stats")
    public Map<String, Object> getExamStatsByUsername(@RequestParam String username) {
        return pastExamService.getExamStatsByUsername(username);
    }
}